package cn.studyjams.s1.contest.autohello.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.studyjams.s1.contest.autohello.R;
import cn.studyjams.s1.contest.autohello.model.ExecuteLog;

public class ExecuteLogAdapter extends RecyclerView.Adapter<ExecuteLogAdapter.ViewHolder> {

    private List<ExecuteLog> mDataset;

    public ExecuteLogAdapter(List<ExecuteLog> myDataset) {
        mDataset = myDataset;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView eventTypeImg;
        TextView eventContent;
        TextView eventReceivers;
        TextView eventExecuteTime;
        TextView eventExecuteResult;

        ViewHolder(View v) {
            super(v);
            eventTypeImg = (ImageView) v.findViewById(R.id.event_type_img);
            eventContent = (TextView) v.findViewById(R.id.event_content);
            eventReceivers = (TextView) v.findViewById(R.id.event_receivers);
            eventExecuteTime = (TextView) v.findViewById(R.id.event_executeTime);
            eventExecuteResult = (TextView) v.findViewById(R.id.event_executeResult);
        }
    }

    @Override
    public ExecuteLogAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.execute_log_item, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        String eventId = mDataset.get(position).getEventId();
        // TODO: 2016/11/30 get event object according to event id
        holder.eventContent.setText(eventId);
        holder.eventReceivers.setText(eventId);
        holder.eventExecuteTime.setText(mDataset.get(position).getExecuteTime());
        holder.eventExecuteResult.setText(mDataset.get(position).getExecuteResult());
    }

    @Override
    public int getItemCount() {
        return mDataset.size();
    }
}
